home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / nn.zip / ACTIVE.C next >
C/C++ Source or Header  |  1989-06-28  |  2KB  |  87 lines

  1. /*
  2.  * read/update incore copy of active file
  3.  */
  4.  
  5. #include "config.h"
  6.  
  7. #ifdef NNTP
  8. char news_active[FILENAME];
  9. #else
  10. char news_active[] = NEWS_ACTIVE;
  11. #endif
  12.  
  13. visit_active_file()
  14. {
  15.     FILE *act;
  16.     char line[512];
  17.     register char *cp, *name;
  18.     register group_header *gh;
  19.     group_header *add_new_group();
  20.  
  21. #ifdef NNTP
  22.     FILE *nntp_act;
  23.     
  24.     nntp_act = NULL;
  25.  
  26.     if (use_nntp)
  27.     nntp_get_active();
  28.     else
  29.     if (is_master)        /* copy 'active' to DB/ACTIVE */
  30.         nntp_act = open_file(relative(db_directory, "ACTIVE"), OPEN_CREATE | MUST_EXIST);
  31. #endif
  32.  
  33.     act = open_file(news_active, OPEN_READ|MUST_EXIST);
  34.     
  35.     while (fgets(line, 512, act)) {
  36. #ifdef NNTP
  37.     if (nntp_act != NULL)
  38.         fputs(line, nntp_act);
  39. #endif    
  40.     cp = line;
  41.     while (*cp && isspace(*cp)) cp++; /* eat blank lines */
  42.     if (*cp == NUL || *cp == '#') continue;
  43.     
  44.     /* cp -> NAME space 00888 ... nl */
  45.     name = cp;
  46.     while (*cp != ' ') cp++;
  47.     *cp++ = NUL;
  48.     
  49.     gh = lookup(name);
  50.     if (gh == NULL) {
  51.         /* new group */
  52.         gh = add_new_group(name);
  53.         if (gh == NULL) continue;
  54.     }
  55.     
  56.     while (*cp && isspace(*cp)) cp++;
  57.     gh->last_article = atol(cp);
  58.  
  59.     while (*cp && isdigit(*cp)) cp++;
  60.     while (*cp && isspace(*cp)) cp++;
  61.     
  62.     if (*cp == NUL) {
  63.         log_entry('E', "Error in active file for entry %s", name);
  64.         continue;
  65.     }
  66.  
  67.     gh->first_article = atol(cp);
  68.     if (gh->first_article == 0) gh->first_article = 1;
  69.  
  70.     while (*cp && isdigit(*cp)) cp++;
  71.     while (*cp && isspace(*cp)) cp++;
  72.     if (*cp == NUL) continue;
  73.     
  74.     if (*cp == 'm') 
  75.         gh->group_flag |= G_MODERATED;
  76.     else
  77.         gh->group_flag &= ~G_MODERATED;
  78.     }
  79.  
  80.     fclose(act);
  81. #ifdef NNTP
  82.     if (nntp_act != NULL)
  83.     fclose(nntp_act);
  84. #endif    
  85. }
  86.  
  87.